package com.ryder.ryderschool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ryder.ryderschool.common.Result;
import com.ryder.ryderschool.entity.Project;
import com.ryder.ryderschool.service.ProjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/projects")
@RequiredArgsConstructor
public class ProjectController {

    private final ProjectService projectService;

    @PostMapping
    public Result<Void> createProject(@RequestBody Project project) {
        projectService.createProject(project);
        return Result.success();
    }

    @PutMapping
    public Result<Void> updateProject(@RequestBody Project project) {
        projectService.updateProject(project);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteProject(@PathVariable Integer id) {
        projectService.deleteProject(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<Project> getProject(@PathVariable Integer id) {
        return Result.success(projectService.getProject(id));
    }

    @GetMapping
    public Result<Page<Project>> listProjects(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String keyword) {
        return Result.success(projectService.listProjects(pageNum, pageSize, keyword));
    }

    @PostMapping("/{id}/submit")
    public Result<Void> submitForReview(@PathVariable Integer id) {
        projectService.submitForReview(id);
        return Result.success();
    }

    @PostMapping("/{id}/first-review")
    public Result<Void> firstReview(
            @PathVariable Integer id,
            @RequestParam boolean approved,
            @RequestParam(required = false) String comment) {
        projectService.firstReview(id, approved, comment);
        return Result.success();
    }

    @PostMapping("/{id}/final-review")
    public Result<Void> finalReview(
            @PathVariable Integer id,
            @RequestParam boolean approved,
            @RequestParam(required = false) String comment) {
        projectService.finalReview(id, approved, comment);
        return Result.success();
    }
} 